package com.example.a2207_zh

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.a2207_zh.adapter.RoomAdapter
import com.example.a2207_zh.databinding.ActivityFangBinding
import com.example.a2207_zh.entity.Rent
import com.example.a2207_zh.mvvm.BaseActivity

class FangActivity : BaseActivity<ActivityFangBinding,FangViewModel>() {
    val list = mutableListOf<Rent>()
    lateinit var roomAdapter: RoomAdapter
    override fun getLayout(): Int = R.layout.activity_fang

    override fun getViewModel(): Class<FangViewModel> = FangViewModel::class.java

    override fun initView() {
        roomAdapter = RoomAdapter(list)
        binding.rv.adapter = roomAdapter

        binding.rv.layoutManager = LinearLayoutManager(this)
        viewModel.room()
    }

    override fun initData() {
        viewModel.success.observe(this){
            if(it.status=="C0000"){
                list.clear()
                list.addAll(it.result.list)
                roomAdapter.notifyDataSetChanged()
            }
        }
    }

}